package io.renren.modules.milk.controller;

import java.util.*;
import io.renren.modules.sys.controller.AbstractController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.renren.modules.milk.entity.MilkRecordEntity;
import io.renren.modules.milk.service.MilkRecordService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import com.alibaba.fastjson.JSON;


/**
 * 牛奶
 * @Author lililiang
 * @Date 2021-07-11 08:54:35
 */
@RestController
@Api(tags = "牛奶")
@RequestMapping("/milk/milkrecord")
public class MilkRecordController extends AbstractController{
    @Autowired
    private MilkRecordService milkRecordService;

    /**
     * 分页查询
     */
    @ApiOperation(value = "分页查询", response = MilkRecordEntity.class)
    @GetMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils pageInfo = milkRecordService.list4Page(params);
        return R.ok().put("page", pageInfo);
    }

    /**
     * 列表查询
     */
    @ApiOperation(value = "列表查询", response = MilkRecordEntity.class)
    @GetMapping("/listByCondition")
    public R listByCondition(@RequestParam Map<String, Object> params){
        List<MilkRecordEntity> list = milkRecordService.listByCondition(params);
        return R.ok().put("list", list);
    }

    /**
     * 列表查询
     */
    @ApiOperation(value = "列表查询", response = MilkRecordEntity.class)
    @GetMapping("/listByConditionYear")
    public R listByConditionYear(@RequestParam Map<String, Object> params){
        List<MilkRecordEntity> list = milkRecordService.listByConditionYear(params);
        return R.ok().put("list", list);
    }

    /**
     * 查询详情
     */
    @ApiOperation(value = "查询详情", response = MilkRecordEntity.class)
    @GetMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
        MilkRecordEntity milkRecord = milkRecordService.queryOneById(id);
        return R.ok().put("milkRecord", milkRecord);
    }

    /**
     * 新增保存
     */
    @ApiOperation(value = "新增保存", response = R.class)
    @PostMapping("/save")
    public R save(@RequestBody MilkRecordEntity entity){
        milkRecordService.insert(entity);
        return R.ok();
    }

    /**
     * 修改保存
     */
    @ApiOperation(value = "修改保存", response = R.class)
    @PostMapping("/update")
    public R update(@RequestBody MilkRecordEntity entity){
		milkRecordService.updateById(entity);
        return R.ok();
    }

    /**
     * 批量逻辑删除
     */
    @ApiOperation(value = "批量逻辑删除", response = R.class)
    @PostMapping("/delete")
    public R delete(@ApiParam(value = "Id数组， 例如 [1,2,3]", required = true) @RequestBody(required = true) String psIds){
		milkRecordService.deleteLogic(JSON.parseArray(psIds, Long.class));
        return R.ok();
    }

}
